package ynu.czs.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ynu.czs.pojo.Cart;
import ynu.czs.pojo.Food;
import ynu.czs.pojo.Result;
import ynu.czs.service.FoodService;

import java.util.List;

@RestController
@RequestMapping("/food")
public class FoodController {
    @Autowired
    private FoodService foodService;

    @GetMapping("/businessId/{businessId}")
    public Result listFoodByBusinessId(@PathVariable("businessId") Integer businessId){
        List<Food> foodList = foodService.listFoodByBusinessId(businessId);
        return Result.success(foodList);
    }

    @GetMapping("/{businessId}/{userId}")
    public Result listFood(@PathVariable("businessId") Integer businessId, @PathVariable("userId") Long userId){
        List<Food> foodList = foodService.listFood(businessId,userId);
        return Result.success(foodList);
    }

    @GetMapping("/getCart/{foodId}/{userId}")
    public Result getCart(@PathVariable("foodId") Integer foodId, @PathVariable("userId") Long userId){
        Cart cart = foodService.getCart(foodId,userId);
        return Result.success(cart);
    }

    @PostMapping()
    public Result addFood(@RequestBody Food food){
        foodService.addFood(food);
        return Result.success();
    }
    @DeleteMapping("/{foodId}")
    public Result deleteFood(@PathVariable("foodId") Integer foodId){
       foodService.deleteFood(foodId);
        return Result.success();
    }

}
